
(function($){
  $(function() {
    $('#myshop').removeClass('dn');
    var vm = new Vue({
      el: '#myshop',
      data: function() {
        return {
          shopInfo: null,
          onWork: 0
        }
      },
      created: function() {
        var _this = this;
        var shop_id = $.getQueryString('shop_id') || ''
        $.mAjax({
          url: '/shop/get-shop-by-myself',
          data: { shop_id: shop_id },
          success: function(res) {
            if (res.status == 1) {
              _this.shopInfo = res.data
              _this.onWork = res.data.on_work
              _this.shop_id = res.data.shop_id
              localStorage.setItem('qrcode', res.data.manager_code_pic);
              localStorage.setItem('shop_id', res.data.shop_id);
            } else {
              if (res.error.errorno == '401') {
                layer.open({
                  content: '登录过期，请重新登录！', skin: 'msg', time: 2 //2秒后自动关闭
                })
                setTimeout(function(){
                  localStorage.removeItem('_u_info_')
                  location.href = './index.html'
                }, 2000)
              }
            }
          } 
        })
      },
      methods: {
        handOkHandler: function() {
          location.href = './hexiao.html'
        },
        toggleWork: function(type) {
          var shop_id = $.getQueryString('shop_id') || ''
          var _this = this;
          if (type == 1) {
            layer.open({
              content: '您确定是否要下班？',
              btn: ['确认', '取消'],
              yes: function(index){
                $.mAjax({
                  url: '/user/on-duty',
                  data: {shop_id: _this.shopInfo.shop_id},
                  success: function(res) {
                    if (res.status == 1) {
                      _this.onWork = 0
                      location.reload()
                      layer.close(index);
                    }
                  }
                })                
              }
            })
          } else {
            layer.open({
              content: '您确定是否上班？',
              btn: ['确认', '取消'],
              yes: function(index){
                $.mAjax({
                  url: '/user/on-duty',
                  data: {shop_id: _this.shopInfo.shop_id},
                  success: function(res) {
                    if (res.status == 1) {
                      _this.onWork = 1
                      location.reload()
                      layer.close(index);
                    } else if (res.status == 0 && res.error.errorno == '100006') {
                      layer.open({
                        content: res.error.errormsg,
                        btn: '我知道了'
                      })
                    } else {
                      if (res.error.errorno == '401') {
                        layer.open({
                          content: '登录过期，请重新登录！',
                          skin: 'msg',
                          time: 2 //2秒后自动关闭
                        })
                        setTimeout(function () {
                          localStorage.removeItem('_u_info_')
                          location.href = './index.html'
                        }, 2000)
                      }
                    }
                  }
                })
              }              
            })            
          }          
        },
        logoutHanlder: function() {
          localStorage.removeItem('_u_info_')
          location.href = './index.html'
        }
      }
    })
  })
})(jQuery)

